import { createStore } from 'vuex'
import { ElMessage } from 'element-plus';
export default createStore({
  state: {
    token: localStorage.getItem('token') || null,
    isLogin: !!localStorage.getItem('token')
  },
  getters: {

  },
  mutations: {
    tokenFun(state, data) {
      if (data) {
        state.token = data
        state.isLogin = true
        window.localStorage.setItem("token", state.token)
      } else {
        state.token = null
        state.isLogin = false
        window.localStorage.removeItem("token")
      }
    },

    outLogin(state) {
      window.localStorage.clear()
      window.sessionStorage.clear()
      state.isLogin = false
      state.token = null
      ElMessage({
        message: '退出成功！',
        type: 'success',
      })
      setTimeout(() => {
        window.location.reload();
      }, 1000);
    }

  },
  actions: {

  },
  modules: {
  }
})
